<template>
    <view class="container">
        <view class="list" v-for="(item, index) in datas.SkuList" :key="index">
            <view class="top">
                <view class="top_left">
                    <view>{{ item.AttributeName ? item.AttributeName : "默认规格" }}</view>
                    <view class="number">货号：{{ item.Sku }}</view>
                </view>
                <view class="top_left">售价：{{ item.SalePrice }}</view>
            </view>
            <view class="body">
                <view class="flex-start" v-for="subitem in item.MenberList">
                    <view class="title">{{ subitem.GradeName }}</view>
                    <view class="flex-start"
                        ><input
                            type="digit"
                            v-model="subitem.Price"
                            placeholder="请输入会员价格"
                            placeholder-class="placeColor" /><text
                            style="padding-left: 18rpx; font-size: 30rpx; color: #333"
                            >元</text
                        ></view
                    >
                </view>
            </view>
        </view>
        <view class="footer">
            <view class="btn btn-success-hollow" @click="submit">保存</view>
        </view>
    </view>
</template>

<script>
import { mapMutations } from "vuex"
import { GetMemberProductInfo, SaveMemberProductInfo } from "@/pages_supplier/service/api/product.js"
export default {
    components: {},
    data() {
        return {
            datas: {},
            id: "",
            look: 0,
            enter: 0,
        }
    },
    onLoad(e) {
        this.id = e.id
    },
    mounted() {},
    onShow() {
        this.getinfo()
    },
    methods: {
        ...mapMutations(["UP_VIP_VIEW"]),
        getinfo() {
            let path = "?productId=" + this.id
            GetMemberProductInfo(path).then((res) => {
                if (res.State == 1) {
                    this.datas = res.Data
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
        del(item, index) {
            if (this.datas.ProductSkuList.length == 1) {
                this.easyToast("无法删除")
            } else {
                this.datas.ProductSkuList.splice(index, 1)
            }
        },
        selectFn(data) {
            const eventChannel = this.getOpenerEventChannel()
            eventChannel.emit("getSelectData", {
                ...data,
            })
            this.easyGoBack()
        },
        submit() {
            let verify = true
            this.datas.SkuList.forEach((e, i) => {
                e.MenberList.forEach((sub, j) => {
                    if (parseInt(sub.Price) < 0) {
                        this.easyToast("请输入正确的会员价")
                        return (verify = false)
                    }
                })
            })
            if (!verify) {
                return
            }
            let parm = {}
            parm.ProductSkuMemberPriceList = []
            this.datas.SkuList.forEach((e, i) => {
                e.MenberList.forEach((sub, j) => {
                    let obj = {}
                    obj.GradeId = sub.ID
                    obj.ProductID = this.id
                    obj.SkuId = e.ID
                    obj.UnitId = e.UnitId
                    obj.MemberSalePrice = sub.Price
                    parm.ProductSkuMemberPriceList.push(obj)
                })
            })
            console.log(parm)
            SaveMemberProductInfo(parm).then((res) => {
                if (res.State == 1) {
                    this.easyToast("保存成功")
                    this.UP_VIP_VIEW(new Date().getTime())
                    setTimeout((e) => {
                        this.easyGoBack()
                    }, 1000)
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
        //导航栏按钮事件
        onNavigationBarButtonTap(e) {
            let index = e.index
            if (index == 0) {
                //历史记录
                this.easyGoTo("/pages_supplier/packet/vipPrice/batchset-price?id=" + this.id)
            }
        },
    },
}
</script>

<style lang="scss">
.container {
    padding: 24rpx 0 130rpx 0;
}
.list {
    padding: 24rpx;
    background: #ffffff;
    margin: 24rpx 24rpx 0 24rpx;
    border-radius: 24rpx;
}
.top {
    font-size: 32rpx;
    color: #333;
    padding: 0 16rpx 16rpx 16rpx;
}

.top_left {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 32rpx;
    font-weight: bold;
    color: $color-gray-1;

    view {
        padding: 0rpx 0 18rpx 0;
    }
}
.body {
    background: #f4f5f6;
    padding: 0 24rpx;
    & > view {
        font-size: 26rpx;
        height: 116rpx;
        color: #333333;
    }
    input {
        width: 292rpx;
        height: 68rpx;
        background: #ffffff;
        border-radius: 4rpx;
        font-size: 32rpx;
        text-indent: 20rpx;
        color: $app-color-main;
        font-weight: bold;
        border-radius: 36rpx;
    }
    .title {
        width: 200rpx;
        padding-bottom: 16rpx;
        font-size: 28rpx;
    }
}
.placeColor {
    font-size: 28rpx;
    color: $color-gray-3;
    font-weight: normal;
}
.btn {
    margin: 16rpx 30rpx 0 30rpx;
}
</style>
